package thread;
/**
 * 中断线程
 */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread wkj = new Thread("王克晶"){
            public void run() {
                System.out.println(getName() +"去睡觉了");
                try {
                    Thread.sleep(50000);
                } catch (InterruptedException e) {
                    System.out.println("谁啊");
                }
                System.out.println(getName() +"睡醒了");
            }
        };
        Thread fcq = new Thread("范传奇"){
            public void run() {
                System.out.println(getName() +"中午吃什么");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(getName() +"问问王克晶吧");
                wkj.interrupt();    //中断睡眠，触发wkj线程的InterruptedException异常
            }
        };
        wkj.start();
        fcq.start();
    }
}
